using System;
using FluentNHibernate.Mapping;
using FluentNHibernate.Conventions;

namespace Caramel.NHibernate.Entities.Conventions
{
	public class GuidIdGeneratorConvention : IIdConvention
	{
		#region IConvention<IIdentityPart> Members

		public bool Accept(IIdentityPart target)
		{
			return true;
		}

		public void Apply(IIdentityPart target)
		{
			target.ColumnName("ID");

			if ((target.IdentityType == typeof(Guid)) || (target.IdentityType == typeof(Guid?)))
			{
				target.GeneratedBy.GuidComb();
			}
		}

		#endregion
	}
}
